package com.bdzl.admin.controller.sys;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.bdzl.pub.entity.sys.FileDO;
import com.bdzl.admin.service.sys.FileService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * -系统文件表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:59:22
 */
 
@Controller
@RequestMapping("/bdzl/file")
public class FileController extends BaseController {
	@Autowired
	private FileService fileService;
	
	@GetMapping()
	String File(){
	    return "bdzl/file/file";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<FileDO> fileList = fileService.list(query);
		int total = fileService.count(query);
		PageUtils pageUtils = new PageUtils(fileList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/file/add";
	}

	@GetMapping("/edit/{fileId}")
	String edit(@PathVariable("fileId") Integer fileId,Model model){
		FileDO file = fileService.get(fileId);
		model.addAttribute("file", file);
	    return "bdzl/file/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody FileDO file){
		R r = new R();
		int a = fileService.save(file);
		if(a>0){
			r.put("fileId",a);
			return r;
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( FileDO file){
		fileService.update(file);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer fileId){
		if(fileService.remove(fileId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] fileIds){
		fileService.batchRemove(fileIds);
		return R.ok();
	}
	
}
